<?php
/*
*All rights reserved: Json.
*Links:http://www.liyaoquan.cn.
*Links:http://imarkchina.cn.
*Links:http://www.imarkchina.cn.
*/

/**
 * 博客后台系统操作模型，负责数据，增，删，改，查
 * 因为没有博客数据没使用数据库，所以没有继承 Model 类
 */
Class GetsystemModel extends PublicModel{

	/**
	 * 博客设置首页数据处理
	 */
	Public function Show(){
		$config = $this->blogConfig();
		return $config;
	}

	/**
	 *保存数据处理
	 * @param [type] $data [description]
	 */
	Public function SaveData($data){
		$file = loadfile(C('config'));
		if (!empty($data['copy_right'])) {
			$data['copy_right'] = str_replace('\\','',$data['copy_right']);
		}if (!empty($data['smtp_code'])) {
			$data['smtp_code'] = str_replace('\\','',$data['smtp_code']);
		}
		if (!empty($data['user_pass'])) {
			$data['user_pass'] = md5($data['user_pass']);
		} else {
			$data['user_pass'] = $file['user_pass'];
		}
		if (isset($data['cacheing'])) {
			if ($data['cacheing'] == '1') {
				$data['cacheing'] = true;
			} else {
				$data['cacheing'] = false;
			}
		}
		$file = array_merge($file, $data);
		if (varfile(C('config'), $file)) {
			return true;
		}
	}

	/**
	 * 显示博客风格文件夹
	 */
	Public function ShowDir(){
		$path = TEMPLATE.'Index/';
		$dh = opendir($path);
		$data = array();
		while(($d = readdir($dh)) != false){
		  if($d == '.' || $d == '..' || $d == 'pinglun'){
		  	continue;
		  }
		  $data[] = $d;
		}
		return $data;
	}
}